<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>李宁体育</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="<%=path%>/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=path%>/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=path%>/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="<%=path%>/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="<%=path%>/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="<%=path%>/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="<%=path%>/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="<%=path%>/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css"
          rel="stylesheet">
    <link href="<%=path%>/css/animate.min.css" rel="stylesheet">
    <link href="<%=path%>/css/style.min862f.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" action="saveCarouselInfo.do" method="post" id="carouselInfoForm" enctype="multipart/form-data">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">排序：</label><font id="errSort" color="red"></font>
                            <div class="col-sm-4">
                                <input id="sort" name="sort" class="form-control" type="text"  maxlength="6"  title="排序" onblur="checkSort();"/>
                            </div>
                        </div>                  
                        <div class="form-group">
                            <label class="col-sm-2 control-label">幻灯片标题：</label><font color="red">*</font>
                            <div class="col-sm-4">
                                <input id="name" name="name" class="form-control" type="text"  maxlength="32" placeholder="请输入标题" title="标题"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">幻灯片图片：</label><font color="red">*</font>
                            <div class="col-sm-4">
                                <input id="picture" name="picture"   type="file"  maxlength="128" title="图片" placeholder="图片" onchange="validateImg();"/>
                                <span id="imgHint" style="color:red">图片比例5：2，建议尺寸750x300px</span>
                                </br>
								<span id="imgsize" style="color:red"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">幻灯片链接：</label><font color="red">*</font>
                            <div class="col-sm-4">
                                <input id="picUrl" name="picUrl" class="form-control" type="text"  title="幻灯片链接" placeholder="幻灯片链接"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">是否显示：</label>
                            <div class="col-sm-4">
                                                                                    是&nbsp;&nbsp;<input  name="isDisplay" checked="checked" type="radio" value="显示"  />&nbsp;&nbsp;&nbsp;&nbsp;
                                                                                    否&nbsp;&nbsp;<input  name="isDisplay"  type="radio" value="不显示"  />
                            </div>
                        </div>                     
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit">提交</button>
                                &nbsp;<button class="btn btn-info" type="button" onclick="goBackCarouselInfo()">返  回</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="<%=path%>/js/jquery.min.js?v=2.1.4"></script>
<script src="<%=path%>/js/bootstrapValidator.min.js"></script>
<!--下拉框-->
<script src="<%=path%>/js/plugins/chosen/chosen.jquery.js"></script>

<script>
function checkSort(){
	 var sort = $("#sort").val();
	 if(sort==null || sort==''){     		
	 }else{
		$.ajax({
	        url: "<%=path%>/carouselInfo/toCheckSort",
	        type: "post",
	        data: {"sort": sort},
	        dataType: "json",
	        success: function (data) {   	              
	              if(data.status=='400'){ 
	            	 $("#errSort").html(data.msg); 
	            	 $("#sort").val("");    	       
	              }  	              
	        },
	        error: function () {
	            alert("异常，请稍后重试");
	        }
	  });
	 }        
}
    var maxsize = 1*1024*1024;  //1M  
    var errMsg = "";
    function validateImg(){
	   var img = $("#picture").val().toLowerCase().split('.');
	   var obj_file = document.getElementById("picture");
	   if(img == ''){   
	   }else{
		   if (img[img.length - 1] == 'gif' || img[img.length - 1] == 'jpg'|| img[img.length - 1] == 'jpeg'|| img[img.length - 1] == 'png') {
			   var filesize = 0;  
               filesize = obj_file.files[0].size
               if(filesize>maxsize){
            	   errMsg = "上传的图片文件不能超过1M！";
            	   $("#imgsize").html(errMsg)
            	   $("#picture").val("");
                   return false;  
               }else{
            	   $("#imgsize").remove();
               }
		   }else{
			   $("#picture").val("");
			   return false;
		   }  
	   }	  
    }
    function goBackCarouselInfo() {
        window.location.href="<%=path%>/carouselInfo/queryCarouselInfoList";
    }
    //表单验证
    var config = {
            ".chosen-select": {},
            ".chosen-select-deselect": {allow_single_deselect: !0},
            ".chosen-select-no-single": {disable_search_threshold: 10},
            ".chosen-select-no-results": {no_results_text: "Oops, nothing found!"},
            ".chosen-select-width": {width: "95%"}
    };
    
    for (var selector in config)$(selector).chosen(config[selector]);
    $(document).ready(function () {
        $('#carouselInfoForm').bootstrapValidator({
            message: 'This value is not valid',
            fields: {
            	sort: {
                    message: '排序不能为空！',
                    validators: {
                        notEmpty: {
                            message: '排序不能为空！'
                        }
                    }
                },
                name: {
                    message: '幻灯片标题不能为空！',
                    validators: {
                        notEmpty: {
                            message: '幻灯片标题不能为空！'
                        }
                    }
                },
                picture: {
                    message: '幻灯片图片不能为空！',
                    validators: {
                        notEmpty: {
                            message: '幻灯片图片不能为空！'
                        }
                    }
                }, 
                picUrl: {
                    message: '幻灯片链接不能为空！',
                    validators: {
                        notEmpty: {
                            message: '幻灯片链接不能为空！'
                        }
                    }
                },
            },
            submitHandler: function(validator, form, submitButton) {
            }
        });
    });
</script>
</body>
</html>
